import traer.physics.*;

class BlockSystem {

  traer.physics.ParticleSystem physics;
  traer.physics.Particle[] particles;

  BlockSystem(int i) {
    if (i == 1) {
      physics = new traer.physics.ParticleSystem(5.0,0.05);
      particles = new traer.physics.Particle[10];
      particles[0] = physics.makeParticle(1.0,width/2,height/2,0);
      particles[0].makeFixed();
      for(int j=1; j < particles.length; ++j) {
        particles[j] = physics.makeParticle(1.0,width/2,height/2+i,0);
        physics.makeSpring(particles[j-1],particles[j],2.0,0.1,0.01);
      }
      particles[particles.length-1].setMass(5.0);
    }
    else {
      physics = new traer.physics.ParticleSystem(5.0,0.05);
      particles = new traer.physics.Particle[2];
      particles[0] = physics.makeParticle(1.0,width/2,height/2,0);
      particles[0].makeFixed();
      particles[1] = physics.makeParticle(1.0,width/2,height/2,0);
      particles[1].makeFixed();
      physics.makeAttraction(particles[0],particles[1],-5000,0);
    }
  }

  void updateAndDraw(){
    PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;         // processings opengl graphics object
    GL gl = pgl.beginGL();
    gl.glEnable(GL.GL_BLEND);
    fadeToColor(gl,0,0,0,0.05);
    //fadeBottom(gl);
    gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
    gl.glEnable(GL.GL_LINE_SMOOTH);
    gl.glLineWidth(1);
    gl.glBegin(GL.GL_QUADS);

    physics.advanceTime(1.0);
    if (mousePressed) {
      particles[particles.length-1].moveTo(mouseX,mouseY,0);
      particles[particles.length-1].velocity().clear();
    }
    drawOldSchool(gl);
    gl.glEnd();
    gl.glDisable(GL.GL_BLEND);
    pgl.endGL();
  }

  void drawOldSchool(GL gl) {
    gl.glColor3f(1.0f,1.0f,1.0f);
    gl.glVertex2f(particles[0].position().x()-30,particles[0].position().y()-10);
    gl.glColor3f(0.0f,0.0f,0.0f);
    gl.glVertex2f(particles[0].position().x()+30,particles[0].position().y()-10);
    gl.glColor3f(1.0f,1.0f,1.0f);
    gl.glVertex2f(particles[0].position().x()+30,particles[0].position().y()+10);
    gl.glColor3f(0.0f,0.0f,0.0f);
    gl.glVertex2f(particles[0].position().x()-30,particles[0].position().y()+10);
    /*    gl.glVertex2f(xpos-2,ypos-2);
     gl.glVertex2f(xpos+2,ypos-2);
     gl.glVertex2f(xpos+2,ypos+2);
     gl.glVertex2f(xpos-2,ypos+2);*/
  }
}






